# -*- bazel -*-

load("@drake//tools/install:install.bzl", "install")
load(
    "@drake//tools/workspace:check_lists_consistency.bzl",
    "check_lists_consistency",
)
load(
    "@drake//tools/workspace:cmake_configure_file.bzl",
    "cmake_configure_file",
)
load("@drake//tools/workspace:generate_file.bzl", "generate_file")
load(
    "@drake//tools/workspace:generate_include_header.bzl",
    "drake_generate_include_header",
)
load("@drake//tools/workspace:vendor_cxx.bzl", "cc_library_vendored")

licenses(["notice"])  # Apache-2.0

package(default_visibility = ["//visibility:private"])

config_setting(
    name = "linux",
    values = {"cpu": "k8"},
)

# Generates config.hh based on the version numbers in CMake code.
cmake_configure_file(
    name = "config",
    src = "include/gz/math/config.hh.in",
    out = "include/gz/math/config.hh",
    cmakelists = ["CMakeLists.txt"],
    defines = [
        "PROJECT_VERSION_MAJOR=0",
        "PROJECT_VERSION_MINOR=0",
        "PROJECT_VERSION_PATCH=0",
        "PROJECT_VERSION=0.0",
        "PROJECT_VERSION_FULL=0.0.0",
        "PROJECT_NAME_NO_VERSION=gz-math",
    ],
)

generate_file(
    name = "include/gz/math/Export.hh",
    content = """
#pragma once
// Simplified version of visibility and deprecation macros.
#define GZ_MATH_VISIBLE
#define GZ_DEPRECATED(version) __attribute__ ((__deprecated__))
    """,
)

_MOST_HDRS = [
    "include/gz/math/AdditivelySeparableScalarField3.hh",
    "include/gz/math/Angle.hh",
    "include/gz/math/AxisAlignedBox.hh",
    "include/gz/math/Box.hh",
    "include/gz/math/Capsule.hh",
    "include/gz/math/Color.hh",
    "include/gz/math/Cone.hh",
    "include/gz/math/CoordinateVector3.hh",
    "include/gz/math/Cylinder.hh",
    "include/gz/math/DiffDriveOdometry.hh",
    "include/gz/math/Ellipsoid.hh",
    "include/gz/math/Filter.hh",
    "include/gz/math/Frustum.hh",
    "include/gz/math/GaussMarkovProcess.hh",
    "include/gz/math/Helpers.hh",
    "include/gz/math/Inertial.hh",
    "include/gz/math/Interval.hh",
    "include/gz/math/Kmeans.hh",
    "include/gz/math/Line2.hh",
    "include/gz/math/Line3.hh",
    "include/gz/math/MassMatrix3.hh",
    "include/gz/math/Material.hh",
    "include/gz/math/MaterialType.hh",
    "include/gz/math/Matrix3.hh",
    "include/gz/math/Matrix4.hh",
    "include/gz/math/Matrix6.hh",
    "include/gz/math/MecanumDriveOdometry.hh",
    "include/gz/math/MovingWindowFilter.hh",
    "include/gz/math/OrientedBox.hh",
    "include/gz/math/PID.hh",
    "include/gz/math/PiecewiseScalarField3.hh",
    "include/gz/math/Plane.hh",
    "include/gz/math/Polynomial3.hh",
    "include/gz/math/Pose3.hh",
    "include/gz/math/Quaternion.hh",
    "include/gz/math/Rand.hh",
    "include/gz/math/Region3.hh",
    "include/gz/math/RollingMean.hh",
    "include/gz/math/RotationSpline.hh",
    "include/gz/math/SemanticVersion.hh",
    "include/gz/math/SignalStats.hh",
    "include/gz/math/SpeedLimiter.hh",
    "include/gz/math/Sphere.hh",
    "include/gz/math/SphericalCoordinates.hh",
    "include/gz/math/Spline.hh",
    "include/gz/math/Stopwatch.hh",
    "include/gz/math/Temperature.hh",
    "include/gz/math/TimeVaryingVolumetricGrid.hh",
    "include/gz/math/TimeVaryingVolumetricGridLookupField.hh",
    "include/gz/math/Triangle.hh",
    "include/gz/math/Triangle3.hh",
    "include/gz/math/Vector2.hh",
    "include/gz/math/Vector3.hh",
    "include/gz/math/Vector3Stats.hh",
    "include/gz/math/Vector4.hh",
    "include/gz/math/VolumetricGridLookupField.hh",
    "include/gz/math/detail/AxisIndex.hh",
    "include/gz/math/detail/Box.hh",
    "include/gz/math/detail/Capsule.hh",
    "include/gz/math/detail/Cone.hh",
    "include/gz/math/detail/Cylinder.hh",
    "include/gz/math/detail/Ellipsoid.hh",
    "include/gz/math/detail/Error.hh",
    "include/gz/math/detail/InterpolationPoint.hh",
    "include/gz/math/detail/Sphere.hh",
    "include/gz/math/detail/WellOrderedVector.hh",
    "include/gz/math/graph/Edge.hh",
    "include/gz/math/graph/Graph.hh",
    "include/gz/math/graph/GraphAlgorithms.hh",
    "include/gz/math/graph/Vertex.hh",
]

_HDRS_PRIVATE = [
    "src/KmeansPrivate.hh",
    "src/MaterialType.hh",
    "src/SplinePrivate.hh",
]

check_lists_consistency(
    files = _MOST_HDRS + _HDRS_PRIVATE,
    glob_include = ["include/**/*.hh"],
    glob_exclude = [
        # These headers are deprecated.
        "include/ignition/math/AdditivelySeparableScalarField3.hh",
        "include/ignition/math/Angle.hh",
        "include/ignition/math/AxisAlignedBox.hh",
        "include/ignition/math/Box.hh",
        "include/ignition/math/Capsule.hh",
        "include/ignition/math/Color.hh",
        "include/ignition/math/Cylinder.hh",
        "include/ignition/math/DiffDriveOdometry.hh",
        "include/ignition/math/Ellipsoid.hh",
        "include/ignition/math/Export.hh",
        "include/ignition/math/Filter.hh",
        "include/ignition/math/Frustum.hh",
        "include/ignition/math/GaussMarkovProcess.hh",
        "include/ignition/math/Helpers.hh",
        "include/ignition/math/Inertial.hh",
        "include/ignition/math/Interval.hh",
        "include/ignition/math/Kmeans.hh",
        "include/ignition/math/Line2.hh",
        "include/ignition/math/Line3.hh",
        "include/ignition/math/MassMatrix3.hh",
        "include/ignition/math/Material.hh",
        "include/ignition/math/MaterialType.hh",
        "include/ignition/math/Matrix3.hh",
        "include/ignition/math/Matrix4.hh",
        "include/ignition/math/Matrix6.hh",
        "include/ignition/math/MecanumDriveOdometry.hh",
        "include/ignition/math/MovingWindowFilter.hh",
        "include/ignition/math/OrientedBox.hh",
        "include/ignition/math/PID.hh",
        "include/ignition/math/PiecewiseScalarField3.hh",
        "include/ignition/math/Plane.hh",
        "include/ignition/math/Polynomial3.hh",
        "include/ignition/math/Pose3.hh",
        "include/ignition/math/Quaternion.hh",
        "include/ignition/math/Rand.hh",
        "include/ignition/math/Region3.hh",
        "include/ignition/math/RollingMean.hh",
        "include/ignition/math/RotationSpline.hh",
        "include/ignition/math/SemanticVersion.hh",
        "include/ignition/math/SignalStats.hh",
        "include/ignition/math/SpeedLimiter.hh",
        "include/ignition/math/Sphere.hh",
        "include/ignition/math/SphericalCoordinates.hh",
        "include/ignition/math/Spline.hh",
        "include/ignition/math/Stopwatch.hh",
        "include/ignition/math/Temperature.hh",
        "include/ignition/math/Triangle.hh",
        "include/ignition/math/Triangle3.hh",
        "include/ignition/math/Vector2.hh",
        "include/ignition/math/Vector3.hh",
        "include/ignition/math/Vector3Stats.hh",
        "include/ignition/math/Vector4.hh",
        "include/ignition/math/VolumetricGridLookupField.hh",
        "include/ignition/math/config.hh",
        "include/ignition/math/detail/AxisIndex.hh",
        "include/ignition/math/detail/Box.hh",
        "include/ignition/math/detail/Capsule.hh",
        "include/ignition/math/detail/Cylinder.hh",
        "include/ignition/math/detail/Ellipsoid.hh",
        "include/ignition/math/detail/Export.hh",
        "include/ignition/math/detail/InterpolationPoint.hh",
        "include/ignition/math/detail/Sphere.hh",
        "include/ignition/math/detail/WellOrderedVector.hh",
        "include/ignition/math/graph/Edge.hh",
        "include/ignition/math/graph/Graph.hh",
        "include/ignition/math/graph/GraphAlgorithms.hh",
        "include/ignition/math/graph/Vertex.hh",
        "include/ignition/math.hh",
    ],
)

_HDRS = _MOST_HDRS + [
    "include/gz/math/config.hh",
    "include/gz/math/Export.hh",
]

# The explicitly listed srcs= matches upstream's explicitly listed sources plus
# private headers.
_SRCS = [
    "src/Angle.cc",
    "src/AxisAlignedBox.cc",
    "src/Color.cc",
    "src/CoordinateVector3.cc",
    "src/DiffDriveOdometry.cc",
    "src/Error.cc",
    "src/Frustum.cc",
    "src/GaussMarkovProcess.cc",
    "src/Helpers.cc",
    "src/Kmeans.cc",
    "src/Material.cc",
    "src/MecanumDriveOdometry.cc",
    "src/PID.cc",
    "src/Rand.cc",
    "src/RollingMean.cc",
    "src/RotationSpline.cc",
    "src/SemanticVersion.cc",
    "src/SignalStats.cc",
    "src/SpeedLimiter.cc",
    "src/SphericalCoordinates.cc",
    "src/Spline.cc",
    "src/SplinePrivate.cc",
    "src/Stopwatch.cc",
    "src/Temperature.cc",
    "src/Vector3Stats.cc",
] + _HDRS_PRIVATE

cc_library_vendored(
    name = "gz_math",
    srcs = _SRCS,
    srcs_vendored = [
        x.replace("src/", "drake_src/src/")
        for x in _SRCS
    ],
    hdrs = _HDRS,
    hdrs_vendored = [
        x.replace("include/gz/", "drake_hdr/gz/")
        for x in _HDRS
    ],
    copts = ["-w"],
    linkstatic = True,
    includes = ["drake_hdr"],
    visibility = ["//visibility:public"],
    deps = [
        "@gz_utils_internal//:gz_utils",
    ],
)

install(
    name = "install",
    docs = ["LICENSE"],
    visibility = ["//visibility:public"],
)
